//
//  NvMakeFilmClipModel.m
//  NvSellerShow
//
//  Created by Meicam on 2017/2/9.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "NvMakeFilmClipModel.h"
#import "Utils.h"

@implementation NvMakeFilmClipModel

-(id)copyWithZone:(NSZone *)zone {
    NvMakeFilmClipModel *model = [[self class] allocWithZone:zone];
    model.clipType = self.clipType;
    model.modelType = self.modelType;
    model.orderId = self.orderId;
    model.clipTitle = [self.clipTitle copyWithZone:zone];
    model.clipPath = [self.clipPath copyWithZone:zone];
    model.clipThumb = [self.clipThumb copy];
    
    model.clipCaption = [self.clipCaption copyWithZone:zone];
    model.captionStyleId = [self.captionStyleId copyWithZone:zone];
    model.triminTimeStamp = [self.triminTimeStamp copyWithZone:zone];
    model.trimoutTimeStamp = [self.trimoutTimeStamp copyWithZone:zone];
    model.audioVolumn = [self.audioVolumn copy];
    model.imageDuration = [self.imageDuration copy];
    model.pan = [self.pan copyWithZone:zone];
    model.scan = [self.scan copyWithZone:zone];
    //sdk中的类暂时没法改
    model.NvsClip = self.NvsClip;
    model.videoSpeed = [self.videoSpeed copyWithZone:zone];
    model.captionScale = [self.captionScale copyWithZone:zone];
    model.stickerScale = [self.stickerScale copyWithZone:zone];
    model.captionOffset = [self.captionOffset copyWithZone:zone];
    model.stickerOffset = [self.stickerOffset copyWithZone:zone];
    
    model.stickerPackageId = [self.stickerPackageId copyWithZone:zone];
    model.videoFx = [self.videoFx copyWithZone:zone];
    
    model.transitionModel = [self.transitionModel copyWithZone:zone];
    
    return model;
}

- (id)init {
    if(self = [super init]){
        _clipType = NvClipNone;
        _modelType = NvMakeFilmClipModelOrigin;
        _audioVolumn = [NSNumber numberWithFloat:-1];
        _triminTimeStamp = [NSNumber numberWithLongLong:0];
        _trimoutTimeStamp = [NSNumber numberWithLongLong:0];
        _imageDuration = [NSNumber numberWithInt:0];
        _pan = [NSNumber numberWithFloat:-2.0];
        _scan = [NSNumber numberWithFloat:-2.0];
        _videoSpeed = [NSNumber numberWithFloat:1.0];
        _captionScale = [NSString stringWithFormat:@"1"];
        _stickerScale = [NSString stringWithFormat:@"1"];
        _captionOffset = NSStringFromCGPoint(CGPointMake(0, 0));
        _stickerOffset = NSStringFromCGPoint(CGPointMake(0, 0));
        
        _captionStyleId = [NSString stringWithFormat:@""];
        _stickerPackageId = [NSString stringWithFormat:@""];
        _videoFx = [NSString stringWithFormat:@"None"];
        
        _transitionModel = [[NvTransitionsModel alloc]initWithImageName:@"" cellImageName:@"无转场" transitionName:@"Fade" transitionSeeName:@""];
    }
    return self;
}

- (id)initWithTitle:(NSString *)title {
    if(self = [super init]){
        _clipType = NvClipNone;
        _modelType = NvMakeFilmClipModelOrigin;
        _clipTitle = title;
        _audioVolumn = [NSNumber numberWithFloat:-1];
        _triminTimeStamp = [NSNumber numberWithLongLong:0];
        _trimoutTimeStamp = [NSNumber numberWithLongLong:0];
        _imageDuration = [NSNumber numberWithInt:0];
        _pan = [NSNumber numberWithFloat:-2.0];
        _scan = [NSNumber numberWithFloat:-2.0];
        _videoSpeed = [NSNumber numberWithFloat:1];
        _captionScale = [NSString stringWithFormat:@"1"];
        _stickerScale = [NSString stringWithFormat:@"1"];
        _captionOffset = NSStringFromCGPoint(CGPointMake(0, 0));
        _stickerOffset = NSStringFromCGPoint(CGPointMake(0, 0));
        _captionStyleId = [NSString stringWithFormat:@""];
        _stickerPackageId = [NSString stringWithFormat:@""];
        _videoFx = [NSString stringWithFormat:@"None"];
        _transitionModel = [[NvTransitionsModel alloc]initWithImageName:@"" cellImageName:@"无转场" transitionName:@"Fade" transitionSeeName:@""];
    }
    return self;
}
- (void)reset {
    _clipType = NvClipNone;
    _modelType = NvMakeFilmClipModelOrigin;
    _clipPath = nil;
    _clipThumb = nil;
    _clipCaption = nil;
    _captionStyleId = nil;
    _audioVolumn = [NSNumber numberWithFloat:-1];
    _triminTimeStamp = [NSNumber numberWithLongLong:0];
    _trimoutTimeStamp = [NSNumber numberWithLongLong:0];
    _imageDuration = [NSNumber numberWithInt:0];
    _NvsClip = nil;
    _pan = [NSNumber numberWithFloat:-2.0];
    _scan = [NSNumber numberWithFloat:-2.0];
    _videoSpeed = [NSNumber numberWithFloat:1.0];
    _captionScale = [NSString stringWithFormat:@"1"];
    _stickerScale = [NSString stringWithFormat:@"1"];
    _captionOffset = NSStringFromCGPoint(CGPointMake(0, 0));
    _stickerOffset = NSStringFromCGPoint(CGPointMake(0, 0));
    _captionStyleId = [NSString stringWithFormat:@""];
    _stickerPackageId = [NSString stringWithFormat:@""];
    _videoFx = [NSString stringWithFormat:@"None"];
    _transitionModel = [[NvTransitionsModel alloc]initWithImageName:@"" cellImageName:@"无转场" transitionName:@"Fade" transitionSeeName:@""];
}

- (id)initWithDraftClip:(NSDictionary *) draftDic{
    if(self = [super init]){
        _clipTitle = [draftDic valueForKey:DraftModelTitleKey];
        _modelType = ((NSNumber *)[draftDic valueForKey:DraftModelTypeKey]).intValue;
        _clipType = ((NSNumber *)[draftDic valueForKey:DraftClipTypeKey]).intValue;
        if(_clipType == NvClipImage) {
            NSString *scaleImageDir = [Utils scaleImageDirectory];
            NSString *imageName = [draftDic valueForKey:DraftClipPathKey];
            _clipPath = [scaleImageDir stringByAppendingPathComponent:imageName];
        }
        else {
            _clipPath = [draftDic valueForKey:DraftClipPathKey];
        }
        _triminTimeStamp = [draftDic valueForKey:DraftVideoClipTrimInKey];
        _trimoutTimeStamp = [draftDic valueForKey:DraftVideoClipTrimOutKey];
        _imageDuration = [draftDic valueForKey:DraftImageClipDurationKey];
        _audioVolumn = [draftDic valueForKey:DraftClipVolumenKey];
        _pan = [draftDic valueForKey:DraftClipPanKey];
        _scan = [draftDic valueForKey:DraftClipScanKey];
        _clipCaption = [draftDic valueForKey:DraftClipCaptionKey];
        _captionStyleId = [draftDic valueForKey:DraftClipCaptionStyleIdKey];
        _clipThumb = [UIImage imageWithData:[draftDic valueForKey:DraftClipThumbDataKey]];
        
        _stickerPackageId = [draftDic valueForKey:DraftStickerPackageID];
        _captionOffset = [draftDic valueForKey:DraftCaptionOffset];
        _stickerOffset = [draftDic valueForKey:DraftStickerOffset];
        
        _captionScale = [draftDic valueForKey:DraftCaptionScale];
        _stickerScale = [draftDic valueForKey:DraftStickerScale];
        
        _videoFx = [draftDic valueForKey:DraftVideoFx];
        
        _transitionModel = [[NvTransitionsModel alloc]initWithImageName:[draftDic valueForKey:DraftTransitionImageNameKey]
                                                          cellImageName:[draftDic valueForKey:DraftTransitionCellImageNameKey]
                                                         transitionName:[draftDic valueForKey:DraftTransitionTransitionNameKey] transitionSeeName:[draftDic valueForKey:DraftTransitionTransitionSeeNameKey]];
        _videoSpeed = [draftDic valueForKey:DraftVideoSpeed];
    }
    return self;
}

- (NSDictionary *)getDraftClipDictionary {
    NSMutableDictionary *draftDictionary = [NSMutableDictionary dictionary];
    [draftDictionary setValue:_clipTitle forKey:DraftModelTitleKey];
    [draftDictionary setValue:[NSNumber numberWithInt:_modelType] forKey:DraftModelTypeKey];
    [draftDictionary setValue:[NSNumber numberWithInt:_clipType] forKey:DraftClipTypeKey];
    if(_clipType == NvClipImage) {
        [draftDictionary setValue:[_clipPath lastPathComponent] forKey:DraftClipPathKey];
    }
    else {
        [draftDictionary setValue:_clipPath forKey:DraftClipPathKey];
    }

    [draftDictionary setValue:_triminTimeStamp forKey:DraftVideoClipTrimInKey];
    [draftDictionary setValue:_trimoutTimeStamp forKey:DraftVideoClipTrimOutKey];
    [draftDictionary setValue:_imageDuration forKey:DraftImageClipDurationKey];
    [draftDictionary setValue:_audioVolumn forKey:DraftClipVolumenKey];
    [draftDictionary setValue:_clipCaption forKey:DraftClipCaptionKey];
    [draftDictionary setValue:_captionStyleId forKey:DraftClipCaptionStyleIdKey];
    [draftDictionary setValue:_pan forKey:DraftClipPanKey];
    [draftDictionary setValue:_scan forKey:DraftClipScanKey];
    NSData * thumbData = UIImageJPEGRepresentation(_clipThumb, 100);
    [draftDictionary setValue:thumbData forKey:DraftClipThumbDataKey];
    
    [draftDictionary setValue:_stickerPackageId forKey:DraftStickerPackageID];
    [draftDictionary setValue:_captionOffset forKey:DraftCaptionOffset];
    [draftDictionary setValue:_stickerOffset forKey:DraftStickerOffset];
    [draftDictionary setValue:_captionScale forKey:DraftCaptionScale];
    [draftDictionary setValue:_stickerScale forKey:DraftStickerScale];
    
    [draftDictionary setValue:_videoFx forKey:DraftVideoFx];
    [draftDictionary setValue:_videoSpeed forKey:DraftVideoSpeed];
    
    [draftDictionary setValue:_transitionModel.imageName forKey:DraftTransitionImageNameKey];
    [draftDictionary setValue:_transitionModel.transitionName forKey:DraftTransitionTransitionNameKey];
    [draftDictionary setValue:_transitionModel.transitionSeeName forKey:DraftTransitionTransitionSeeNameKey];
    [draftDictionary setValue:_transitionModel.cellImageName forKey:DraftTransitionCellImageNameKey];
    
    
    return draftDictionary.copy;
}

@end
